<template>
  <div class="singer-list">
    <h1 class="list-title">热门歌手</h1>
    <div class="singer-container">
      <el-card
        v-for="singer in singerList"
        :key="singer.singerId"
        class="singer-card"
      >
        <div class="card-content" @click="handleSingerClick(singer.singerId)">
          <div class="avatar-container">
            <image-preview
              :src="singer.avatarUrl"
              :width="200"
              :height="200"
              class="singer-avatar"
            />
          </div>
          <div class="singer-info">
            <div class="singer-name">{{ singer.singerName }}</div>
            <!-- <div class="singer-fans">粉丝数: {{ singer.fans }}0k</div> -->
          </div>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import { listSingerByKeyWord } from "@/api/singer/singer"; // 假设有一个 API 获取歌手列表

export default {
  name: "SingerList",
  data() {
    return {
      keyword: "", // 用于存储搜索关键词
      singerList: [], // 用于存储歌手列表
    };
  },
  created() {
    this.keyword = this.$route.query.keyword; // 获取路由参数中的 keyword
    console.log("关键词为：", this.keyword);
    this.getSingerList(); // 页面创建时获取歌手列表
  },
  methods: {
    getSingerList() {
      listSingerByKeyWord(this.keyword)
        .then((response) => {
          this.singerList = response; // 假设 API 返回的数据结构
          console.log("获取的歌手列表:", response);
        })
        .catch((error) => {
          console.error("获取歌手列表失败:", error);
        });
    },
    handleSingerClick(singerId) {
      this.$router.push({
        path: "/userSinger",
        query: { singerId: singerId },
      });
    },
  },
};
</script>

<style scoped>
.singer-list {
  padding: 30px 5%;
  background-color: #f8f9fa;
}

.list-title {
  text-align: center;
  margin-bottom: 40px;
  color: #2c3e50;
  font-size: 2.5rem;
}

.singer-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 30px;
  justify-content: center;
}

.singer-card {
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  background: #ffffff;
}

.singer-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.card-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.avatar-container {
  width: 100%;
  padding-top: 100%; /* 保持1:1比例 */
  position: relative;
  overflow: hidden;
  background: #f0f0f0;
}

.singer-avatar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.singer-card:hover .singer-avatar {
  transform: scale(1.05);
}

.singer-info {
  padding: 16px;
  text-align: center;
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.singer-name {
  font-size: 1.1rem;
  font-weight: 600;
  color: #34495e;
  margin-bottom: 8px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.singer-fans {
  font-size: 0.9rem;
  color: #7f8c8d;
  margin-top: auto;
}

@media (max-width: 768px) {
  .singer-container {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
  }

  .list-title {
    font-size: 2rem;
  }
}
</style>
